package com.naxian.service.Impl;

import com.naxian.mapper.*;
import com.naxian.pojo.*;

import com.naxian.service.jobApplication.JobApplicationService;
import com.naxian.vo.MyApplication;
import com.naxian.vo.MyApplicationVO;
import com.sun.org.apache.regexp.internal.RE;
import com.sun.scenario.effect.impl.sw.sse.SSEBlend_SRC_OUTPeer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.zip.CRC32;

@Service
public class JobApplicationServiceImpl implements JobApplicationService {
    @Autowired
    private InterviewInvitationMapper interviewInvitationMapper;
    @Autowired
    private ResumesMapper resumesMapper;
    @Autowired
    private CompanyReceivedMapper companyReceivedMapper;
    @Autowired
    private RecruitMapper recruitMapper;
    @Autowired
    private CompanyMapper companyMapper;
//    public List<MyApplication> getByPerId(Integer perId) {
//        List<MyApplication> myApplications = null;
//        MyApplication myApplication = new MyApplication();
//        ResumesExample resumesExample = new ResumesExample();
//        ResumesExample.Criteria criteria = resumesExample.createCriteria();
//        criteria.andPerIdEqualTo(perId);
//        List<Resumes> resumesList = resumesMapper.selectByExample(resumesExample);
//        for (Resumes r:resumesList){
//            myApplications = new ArrayList<>();
//            int resId = r.getResumeId();
//            CompanyReceivedExample companyReceivedExample = new CompanyReceivedExample();
//            CompanyReceivedExample.Criteria criteria1 = companyReceivedExample.createCriteria();
//            criteria1.andResumeIdEqualTo(resId);
//            List<CompanyReceived> companyReceiveds = companyReceivedMapper.selectByExample(companyReceivedExample);
//
//            for (CompanyReceived c:companyReceiveds){
//                int recId = c.getRecId();
//                int comRecId =c.getCompanyReceiveId();
//                CompanyReceived companyReceived = companyReceivedMapper.selectByPrimaryKey(comRecId);
//                Recruit recruit = recruitMapper.selectByPrimaryKey(recId);
//                int companyId =  recruit.getCompanyId();
//                Company company = companyMapper.selectByPrimaryKey(companyId);
//                myApplication.setCompany(company);
//                myApplication.setCompanyReceived(companyReceived);
//                myApplication.setRecruit(recruit);
//                myApplications.add(myApplication);
//
//            }
//
//        }
//        return myApplications;
//
//    }

    @Override
    public InterviewInvitation selectById(Integer invitationId) {
        InterviewInvitation interviewInvitation = interviewInvitationMapper.selectByPrimaryKey(invitationId);
        return interviewInvitation;
    }


    @Override
    public MyApplication getByPerId(Integer perId){
//        List<MyApplication> myApplicationList = new ArrayList<>();
        List<MyApplicationVO> myApplicationVOList = new ArrayList<>();

        MyApplication myApplication = new MyApplication();
        ResumesExample resumesExample = new ResumesExample();
        ResumesExample.Criteria resumerCriteria = resumesExample.createCriteria();
        resumerCriteria.andPerIdEqualTo(perId);
        List<Resumes> resumesList = resumesMapper.selectByExample(resumesExample);
        System.out.println("RRRR====="+resumesList);
        for (Resumes r:resumesList){

            //Resumes resumes = resumesMapper.selectByPrimaryKey(r.getResumeId());
            CompanyReceivedExample companyReceivedExample = new CompanyReceivedExample();
            CompanyReceivedExample.Criteria companyRecCriteria = companyReceivedExample.createCriteria();
            companyRecCriteria.andResumeIdEqualTo(r.getResumeId());
            List<CompanyReceived> companyReceivedList = companyReceivedMapper.selectByExample(companyReceivedExample);
            for (CompanyReceived cr:companyReceivedList){

                CompanyReceived companyReceived = companyReceivedMapper.selectByPrimaryKey(cr.getCompanyReceiveId());
                Recruit recruit = recruitMapper.selectByPrimaryKey(cr.getRecId());
                Company company = companyMapper.selectByPrimaryKey(recruit.getCompanyId());

                MyApplicationVO myApplicationVO =new MyApplicationVO(company,recruit,companyReceived);
                System.out.println("||||||||||||||||||||||||||||||||||||||||");
                System.out.println("123myApplicationVO======"+myApplicationVO);
//                myApplicationList.add(myApplication);
//                System.out.println("MMMMM======="+myApplication);
//                System.out.println("VO====="+

                myApplicationVOList.add(myApplicationVO);//此集合中的数据是最后需要得到的
            }
        }
        myApplication.setMyApplicationVOList(myApplicationVOList);

        System.out.println("123344========"+myApplication);
        return myApplication;
    }
}
